package com.triones.ljr.controller.web;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.dtflys.forest.annotation.Post;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.vo.SysUserExportVo;
import com.triones.ljr.entity.bo.DeclareAuditParams;
import com.triones.ljr.entity.bo.DeclareSysAuditBO;
import com.triones.ljr.entity.dto.DeclareAuditDO;
import com.triones.ljr.entity.vo.CustomDeclareAuditExportVo;
import com.triones.ljr.entity.vo.CustomDeclareAuditVO;
import com.triones.ljr.service.DeclareAuditService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 申报审核
 *
 * @Author: triones
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/declareAudit")
public class DeclareAuditController extends BaseController {

    private final DeclareAuditService declareAuditService;

    /**
     * 列表（分页）
     */
    @SaCheckPermission("system:shPolicyAudit:pageList")
    @GetMapping("/pageList")
    public TableDataInfo<CustomDeclareAuditVO> pageList(DeclareAuditParams params, PageQuery pageQuery) {
        return declareAuditService.pageList(params, pageQuery);
    }

    /**
     * 审核
     */
    @SaCheckPermission("system:shPolicyAudit:edit")
    @Log(title = "申报审核", businessType = BusinessType.INSERT)
    @PostMapping("/audit")
    public R<Void> audit(@Validated @RequestBody DeclareSysAuditBO bo) {
        return toAjax(declareAuditService.audit(bo));
    }

    /**
     * 兑现
     */
    @SaCheckPermission("system:shPolicyAudit:fulfill")
    @Log(title = "申报审核", businessType = BusinessType.INSERT)
    @PostMapping("/fulfill")
    public R<Void> fulfill(@RequestBody DeclareSysAuditBO bo) {
        return toAjax(declareAuditService.fulfill(bo));
    }

    /**
     * 导出列表
     */
    @Log(title = "申报审核", businessType = BusinessType.EXPORT)
    @PostMapping("/export/{idsArr}")
    public void export(@PathVariable Long[] idsArr, HttpServletResponse response) {
        List<Long> ids = Arrays.asList(idsArr);
        List<CustomDeclareAuditVO> list = declareAuditService.selectListByIds(ids);
        List<CustomDeclareAuditExportVo> listVo = BeanUtil.copyToList(list, CustomDeclareAuditExportVo.class);
        ExcelUtil.exportExcel(listVo, "用户数据", CustomDeclareAuditExportVo.class, response);
    }

    /**
     * 删除
     */
    @SaCheckPermission("system:shPolicyAudit:remove")
    @Log(title = "申报审核", businessType = BusinessType.INSERT)
    @DeleteMapping("/{id}")
    public R<Void> remove(@PathVariable Long id) {
        return toAjax(declareAuditService.remove(id));
    }
}
